home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / System Extensions / MIDI Management Tools 2.0.2 / Interfaces & Glue / MIDI.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-10  |  12.4 KB  |  388 lines  |  [TEXT/MPS ]

  1.  
  2. /* 
  3.  *  MIDI.h
  4.  * 
  5.  *  This file contains the c-language interface for the MIDI Manager.
  6.  * 
  7.  *  Author: John Worthington, Don Marsh, Mark Lentczner
  8.  *  Copyright © 1988-90, Apple Computer, Inc.
  9.  *  All Rights Reserved
  10.  *
  11.  *  Version 2.0a1
  12.  */
  13.  
  14. #ifndef __MIDI__
  15. #define __MIDI__
  16.  
  17. #include <Types.h>
  18.                 
  19.  
  20. /* 
  21.  *  Constants:
  22.  */
  23.  
  24. #define midiToolNum            4        /*tool number of MIDI Manager for SndDispVersion call*/
  25.  
  26. #define midiMaxNameLen        31        /*maximum number of characters in port and client names*/
  27.  
  28.  
  29.     /*Time formats*/
  30.  
  31. #define midiFormatMSec        0        /*milliseconds*/
  32. #define midiFormatBeats        1        /*beats*/
  33. #define midiFormat24fpsBit    2        /*24 frames/sec.*/
  34. #define midiFormat25fpsBit    3        /*25 frames/sec.*/
  35. #define midiFormat30fpsDBit    4        /*30 frames/sec. drop-frame*/
  36. #define midiFormat30fpsBit    5        /*30 frames/sec.*/
  37. #define midiFormat24fpsQF    6        /*24 frames/sec. longInt format */
  38. #define midiFormat25fpsQF    7        /*25 frames/sec. longInt format */
  39. #define midiFormat30fpsDQF    8        /*30 frames/sec. drop-frame longInt format */
  40. #define midiFormat30fpsQF    9        /*30 frames/sec. longInt format */
  41.  
  42. #define    midiInternalSync    0        /*internally synced*/
  43. #define    midiExternalSync    1        /*externally synced*/
  44.  
  45.     /*Port types*/
  46.  
  47. #define midiPortTypeTime    0        /*time port*/
  48. #define midiPortTypeInput    1        /*input port*/
  49. #define midiPortTypeOutput    2        /*output port*/
  50. #define midiPortTypeTimeInv    3        /*invisible time port*/
  51. #define midiPortInvisible    0x8000  /*add this to other types to make invisible ports */
  52. #define midiPortTypeMask    0x0007    /*AND with this to convert new port types to old,
  53.                                         ie. to strip the property bits */
  54.  
  55.     /*OffsetTimes*/
  56.  
  57. #define midiGetEverything    0x7FFFFFFF    /*get all packets, regardless of time stamps*/
  58. #define midiGetNothing        0x80000000    /*get no packets, regardless of time stamps*/
  59. #define midiGetCurrent        0x00000000    /*get current packets only*/
  60.                 
  61.  
  62.  
  63. /* 
  64.  *  MIDI data and messages are passed in MIDIPacket records (see below).
  65.  *  The first byte of every MIDIPacket contains a set of flags
  66.  * 
  67.  *  bits 0-1    00 = new MIDIPacket, not continued
  68.  *                 01 = begining of continued MIDIPacket
  69.  *                 10 = end of continued MIDIPacket
  70.  *                 11 = continuation
  71.  *  bits 2-3    reserved
  72.  * 
  73.  *     bits 4-6    000 = packet contains MIDI data
  74.  *                 001 = packet contains MIDI Manager message
  75.  * 
  76.  *  bit 7        0 = MIDIPacket has valid stamp
  77.  *                1 = stamp with current clock
  78.  *                 
  79.  */
  80.  
  81. #define midiContMask        0x03
  82. #define midiNoCont            0x00
  83. #define midiStartCont        0x01
  84. #define midiMidCont            0x03
  85. #define midiEndCont            0x02
  86.  
  87. #define midiTypeMask        0x70
  88. #define midiMsgType            0x00
  89. #define midiMgrType            0x10
  90.  
  91. #define midiTimeStampMask        0x80
  92. #define midiTimeStampCurrent    0x80
  93. #define midiTimeStampValid        0x00
  94.  
  95.  
  96. /*
  97.  *  MIDI Manager MIDIPacket command words (the first word in the data field
  98.  *  for midiMgrType messages)
  99.  */
  100.  
  101. #define midiOverflowErr        0x0001
  102. #define midiSCCErr            0x0002
  103. #define midiPacketErr        0x0003
  104. #define midiMaxErr            0x00FF            /*all command words less than this value*/
  105.                                             /*  are error indicators*/
  106.  
  107.     /* Valid results to be returned by readHooks */
  108.  
  109. #define midiKeepPacket        0
  110. #define midiMorePacket        1
  111. #define midiNoMorePacket    2
  112. #define midiHoldPacket         3
  113.  
  114.  
  115. /* 
  116.  *  Errors:
  117.  */
  118.  
  119. #define midiNoClientErr        -250    /*no client with that ID found*/
  120. #define midiNoPortErr        -251    /*no port with that ID found*/
  121. #define midiTooManyPortsErr    -252    /*too many ports already installed in the system*/
  122. #define midiTooManyConsErr    -253    /*too many connections made*/
  123. #define midiVConnectErr        -254    /*pending virtual connection created*/
  124. #define midiVConnectMade    -255    /*pending virtual connection resolved*/
  125. #define midiVConnectRmvd    -256    /*pending virtual connection removed*/
  126. #define midiNoConErr        -257    /*no connection exists between specified ports*/
  127. #define midiWriteErr        -258    /*MIDIWritePacket couldn't write to all connected ports*/
  128. #define midiNameLenErr        -259    /*name supplied is longer than 31 characters*/
  129. #define midiDupIDErr        -260    /*duplicate client ID*/
  130. #define midiInvalidCmdErr    -261    /*command not supported for port type*/
  131.  
  132.  
  133. /* 
  134.  *  Driver calls:
  135.  */
  136.  
  137. #define midiOpenDriver        1
  138. #define midiCloseDriver        2
  139.  
  140.  
  141. /* 
  142.  *  MIDI data and other messages are read and written via packets:
  143.  */
  144.  
  145. typedef struct MIDIPacket {
  146.     unsigned char    flags;
  147.     unsigned char    len;
  148.     long            tStamp;
  149.     unsigned char    data[249];
  150. } MIDIPacket;
  151.  
  152. typedef MIDIPacket        *MIDIPacketPtr;
  153.  
  154.                 
  155.  
  156. /* 
  157.  *  Clocks:
  158.  */
  159.  
  160. typedef struct MIDIClkInfo {
  161.     short    sync;            /*synchronization external/internal*/
  162.     long    curTime;        /*current value of port's clock*/
  163.     short    format;            /*time code format*/
  164. } MIDIClkInfo;
  165.  
  166.  
  167. /* 
  168.  *  port information
  169.  */
  170.  
  171. typedef struct MIDIIDRec {
  172.     OSType    clientID;
  173.     OSType    portID;
  174. } MIDIIDRec;
  175.  
  176.  
  177. typedef struct MIDIPortInfo {
  178.     short        type;            /*type of port*/
  179.     MIDIIDRec    timeBase;        /*MIDIIDRec for time base*/
  180.     short        numConnects;    /*number of connections*/
  181.     MIDIIDRec    cList[];        /*ARRAY [1..numConnects] of MIDIIDRec */
  182. } MIDIPortInfo;
  183.                     
  184. typedef MIDIPortInfo    *MIDIPortInfoPtr, **MIDIPortInfoHdl;
  185.  
  186.  
  187. typedef struct MIDIPortParams {
  188.     OSType    portID;            /*ID of port, unique within client*/
  189.     short    portType;        /*Type of port - input, output, time, etc.*/
  190.     short    timeBase;        /*refnum of time base, 0 if none*/
  191.     long    offsetTime;        /*offset for current time stamps*/
  192.     Ptr        readHook;        /*routine to call when input data is valid*/
  193.     long    refCon;            /*refcon for port (for client use)*/
  194.     MIDIClkInfo    initClock;    /*initial settings for a time base*/
  195.     Str255    name;            /*name of the port, This is a real live string, not a ptr.*/
  196. } MIDIPortParams;
  197.  
  198. typedef MIDIPortParams    *MIDIPortParamsPtr;
  199.  
  200.  
  201.  
  202. /*
  203.  *    ID List
  204.  */
  205.  
  206. typedef struct MIDIIDList {
  207.     short    numIDs;
  208.     OSType    list[];
  209. } MIDIIDList;
  210.  
  211. typedef MIDIIDList        *MIDIIDListPtr, **MIDIIDListHdl;
  212.  
  213. /* 
  214.  * MDVR Control structs
  215.  *
  216.  */
  217.  
  218.  typedef struct MDVRInCtlRec {
  219.     short     timeCodeClock;    /* refnum of time base for time code */
  220.     short     timeCodeFormat;    /* format of time code output */
  221.     ProcPtr    readProc;        /* proc to call with intput characters */
  222.     ProcPtr commProc;        /* proc to call for handshaking */
  223.     long     refCon            /* refCon passed to readProc, commProc */
  224. } MDVRInCtlRec;
  225.  
  226. typedef MDVRInCtlRec    *MDVRInCtlPtr;
  227.  
  228.  
  229. typedef struct MDVROutCtlRec  {
  230.     short        timeCodeClock;    /* time base driven by time code */
  231.     short        timeCodeFormat; /* format of time code to listen to */
  232.     ProcPtr        timeCodeProc;    /* proc called on time code fmt change */
  233.     ProcPtr        commProc;        /* proc called for handshaking */
  234.     long        refCon;            /* refCon passed to timeCodeProc */
  235.     Boolean        timeCodeFilter;    /* filter time code if true */
  236.     long        midiMsgTicks;    /* value of Ticks when MIDI msg rcvd */
  237.     long        timeCodeTicks;    /* value of Ticks when time code rcvd */
  238. } MDVROutCtlRec;
  239.  
  240. typedef MDVROutCtlRec    *MDVROutCtlPtr;
  241.  
  242. typedef void *MDVRPtr;
  243.  
  244. #define    mdvrAbortNotesOff 0;    /* abort previous mdvrNotesOff request */
  245. #define    mdvrChanNotesOff 1;        /* generate channel note off messages  */
  246. #define    mdvrAllNotesOff 2;        /* generate all note off messages     */
  247.  
  248. #define mdvrStopOut 0;            /* stop calling MDVROut temporarily */
  249. #define mdvrStartOut 1;            /* resume calling MDVROut */
  250.  
  251.  
  252. /*
  253.  *    Prototype Declarations for readHook and timeProc
  254.  *
  255.  *    extern pascal short myReadHook(MIDIPacketPtr myPacket, long myRefCon);
  256.  *    extern pascal void myTimeProc(long curTime, long myRefCon);
  257.  *    extern pascal void connectionProc(short refnum, long refcon, short portType
  258.  *                OSType clientID, OSType portID, BOOLEAN connect, short direction);
  259.  *
  260.  *
  261.  */
  262.  
  263. /*
  264.  *     Protype Declarations for driver routines
  265.  *
  266.  *
  267.  *     extern pascal long CommProc(short refnum, short request, long refCon); 
  268.  *    extern pascal void TimeCodeProc(short refnum, short newFormat, long refCon);
  269.  *    extern pascal void ReadProc (char *midiChars, short length, long refCon);
  270.  *
  271.  */
  272.  
  273.  
  274.  
  275. /* MIDI Manager Routines */            
  276.  
  277. pascal long SndDispVersion(short toolnum) extern;
  278.  
  279. pascal OSErr MIDISignIn(OSType clientID, long refCon, Handle icon, Str255 name)
  280.     = {0x203C,4,midiToolNum,0xA800};
  281. pascal void MIDISignOut(OSType clientID)
  282.     = {0x203C,8,midiToolNum,0xA800};
  283. pascal MIDIIDListHdl MIDIGetClients()
  284.     = {0x203C,12,midiToolNum,0xA800};
  285. pascal void MIDIGetClientName(OSType clientID, Str255 name)
  286.     = {0x203C,16,midiToolNum,0xA800};
  287. pascal void MIDISetClientName(OSType clientID, Str255 name)
  288.     = {0x203C,20,midiToolNum,0xA800};
  289. pascal MIDIIDListHdl MIDIGetPorts(OSType clientID)
  290.     = {0x203C,24,midiToolNum,0xA800};
  291. pascal OSErr MIDIAddPort(OSType clientID, short BufSize, short *refnum, MIDIPortParamsPtr init)
  292.     = {0x203C,28,midiToolNum,0xA800};
  293. pascal MIDIPortInfoHdl MIDIGetPortInfo(OSType clientID, OSType portID)
  294.     = {0x203C,32,midiToolNum,0xA800};
  295. pascal OSErr MIDIConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  296.     = {0x203C,36,midiToolNum,0xA800};
  297. pascal OSErr MIDIUnConnectData(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  298.     = {0x203C,40,midiToolNum,0xA800};
  299. pascal OSErr MIDIConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  300.     = {0x203C,44,midiToolNum,0xA800};
  301. pascal OSErr MIDIUnConnectTime(OSType srcClID, OSType srcPortID, OSType dstClID, OSType dstPortID)
  302.     = {0x203C,48,midiToolNum,0xA800};
  303. pascal void MIDIFlush(short refnum)
  304.     = {0x203C,52,midiToolNum,0xA800};
  305. pascal ProcPtr MIDIGetReadHook(short refnum)
  306.     = {0x203C,56,midiToolNum,0xA800};
  307. pascal void MIDISetReadHook(short refnum, ProcPtr hook)
  308.     = {0x203C,60,midiToolNum,0xA800};
  309. pascal void MIDIGetPortName(OSType clientID, OSType portID, Str255 name)
  310.     = {0x203C,64,midiToolNum,0xA800};
  311. pascal void MIDISetPortName(OSType clientID, OSType portID, Str255 name)
  312.     = {0x203C,68,midiToolNum,0xA800};
  313. pascal void MIDIWakeUp(short refnum, long time, long period, ProcPtr timeProc)
  314.     = {0x203C,72,midiToolNum,0xA800};
  315. pascal void MIDIRemovePort(short refnum)
  316.     = {0x203C,76,midiToolNum,0xA800};
  317. pascal short MIDIGetSync(short refnum) 
  318.     = {0x203C,80,midiToolNum,0xA800};
  319. pascal void MIDISetSync(short refnum, short sync)
  320.     = {0x203C,84,midiToolNum,0xA800};
  321. pascal long MIDIGetCurTime(short refnum)
  322.     = {0x203C,88,midiToolNum,0xA800};
  323. pascal void MIDISetCurTime(short refnum, long time)
  324.     = {0x203C,92,midiToolNum,0xA800};
  325. pascal void MIDIStartTime(short refnum)
  326.     = {0x203C,96,midiToolNum,0xA800};
  327. pascal void MIDIStopTime(short refnum)
  328.     = {0x203C,100,midiToolNum,0xA800};
  329. pascal void MIDIPoll(short refnum, long offsetTime)
  330.     = {0x203C,104,midiToolNum,0xA800};
  331. pascal OSErr MIDIWritePacket(short refnum, MIDIPacketPtr packet)
  332.     = {0x203C,108,midiToolNum,0xA800};
  333. pascal Boolean MIDIWorldChanged(OSType clientID)
  334.     = {0x203C,112,midiToolNum,0xA800};
  335. pascal long MIDIGetOffsetTime(short refnum)
  336.     = {0x203C,116,midiToolNum,0xA800};
  337. pascal void MIDISetOffsetTime(short refnum, long offsetTime)
  338.     = {0x203C,120,midiToolNum,0xA800};
  339. pascal long MIDIConvertTime(short srcformat, short dstformat, long time)
  340.     = {0x203C,124,midiToolNum,0xA800};
  341. pascal long MIDIGetRefCon(short refnum)
  342.     = {0x203C,128,midiToolNum,0xA800};
  343. pascal void MIDISetRefCon(short refnum, long refCon)
  344.     = {0x203C,132,midiToolNum,0xA800};
  345. pascal long MIDIGetClRefCon(OSType clientID)
  346.     = {0x203C,136,midiToolNum,0xA800};
  347. pascal void MIDISetClRefCon(OSType clientID, long refCon)
  348.     = {0x203C,140,midiToolNum,0xA800};
  349. pascal short MIDIGetTCFormat(short refnum)
  350.     = {0x203C,144,midiToolNum,0xA800};
  351. pascal void MIDISetTCFormat(short refnum, short format)
  352.     = {0x203C,148,midiToolNum,0xA800};
  353. pascal void MIDISetRunRate(short refnum, short rate, long time)
  354.     = {0x203C,152,midiToolNum,0xA800};
  355. pascal Handle MIDIGetClientIcon(OSType clientID)
  356.     = {0x203C,156,midiToolNum,0xA800};
  357. pascal ProcPtr MIDICallAddress(short callNum)
  358.     = {0x203C,164,midiToolNum,0xA800};
  359. pascal void MIDISetConnectionProc(short refNum, ProcPtr connectionProc, long refCon)
  360.     = {0x203C,168,midiToolNum,0xA800};
  361. pascal void MIDIGetConnectionProc(short refnum, ProcPtr *connectionProc, long *refCon)
  362.     = {0x203C, 172,midiToolNum,0xA800};
  363. pascal void MIDIDiscardPacket(short refnum, MIDIPacketPtr packet)
  364.     = {0x203C, 176,midiToolNum,0xA800};
  365. pascal OSErr MDVRSignIn(OSType clientID, long refCon, Handle icon, Str255 name)
  366.     = {0x203C,180,midiToolNum,0xA800};
  367. pascal void MDVRSignOut(OSType clientID)
  368.     = {0x203C,184,midiToolNum,0xA800};
  369. pascal MDVRPtr MDVROpen(short portType, short refnum)
  370.     = {0x203C,188,midiToolNum,0xA800};
  371. pascal void MDVRClose(MDVRPtr driverPtr)
  372.     = {0x203C,192,midiToolNum,0xA800};
  373. pascal void MDVRControlIn(MDVRPtr portPtr, MDVRInCtlPtr inputCtl)
  374.     = {0x203C,196,midiToolNum,0xA800};
  375. pascal void MDVRControlOut(MDVRPtr portPtr, MDVROutCtlPtr outputCtl)
  376.     = {0x203C,200,midiToolNum,0xA800};
  377. pascal void MDVRIn(MDVRPtr portPtr)
  378.     = {0x203C,204,midiToolNum,0xA800};
  379. pascal void MDVROut(MDVRPtr portPtr, char *dataPtr, short length)
  380.     = {0x203C,208,midiToolNum,0xA800};
  381. pascal void MDVRNotesOff(MDVRPtr portPtr, short mode)
  382.     = {0x203C,212,midiToolNum,0xA800};
  383.     
  384.     
  385. #endif
  386.  
  387.  
  388.